package com.chance.cc.crawler.development.command.meta.keyword.weibo;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.development.command.meta.keyword.CrawlerDomainKeywordCommand;
import com.chance.cc.crawler.meta.core.bean.crawler.CrawlerDomainKeys;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;

import static com.chance.cc.crawler.development.command.job.domain.weibo.WeiboCommonScript.geelyKwSite;

/**
 * @Author Zhao.Hhuan
 * @Date Create in 2020/12/29 10:34
 * @Description
 *      微博关键词
 **/
@Data
@AllArgsConstructor
public class WeiboSearchKwList {

    private static final String domian = "weibo";
    private static final String site = "searchKw";

    public static void main(String[] args) throws IOException {
//        geelyKeyWord();
        userIdSub();
    }

    public static void keyword(){
        try{
            List<String> kwLines = IOUtils.readLines(new FileInputStream("F:\\chance_work\\chance-crawler-development\\crawler-scripts-command\\src\\main\\java\\com\\chance\\cc\\crawler\\development\\command\\meta\\keyword\\weibo\\weibo_search_kw_test.txt"), Charset.forName("UTF-8"));

            for (String kwLine : kwLines) {
                if (kwLine.startsWith("#")){
                    continue;
                }
                CrawlerDomainKeywordCommand crawlerDomainKeywordCommand = new CrawlerDomainKeywordCommand("192.168.1.215",9599);

                CrawlerDomainKeys crawlerDomainKeys = new CrawlerDomainKeys();
                crawlerDomainKeys.setDomain(domian);
                crawlerDomainKeys.setKeyword(kwLine);
                crawlerDomainKeys.setSite(site);
                crawlerDomainKeys.setStatus(0);
                crawlerDomainKeywordCommand.addOrUpdateKeys(crawlerDomainKeys);

                System.out.println(JSON.toJSONString(kwLine));
            }
        } catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
    public static void geelyKeyWord(){
        try{
            List<String> kwLines = IOUtils.readLines(new FileInputStream("E:\\chance_work\\chance-crawler-development\\crawler-scripts-command\\src\\main\\java\\com\\chance\\cc\\crawler\\development\\command\\meta\\keyword\\weibo\\geely_keyword.txt"), Charset.forName("UTF-8"));

            for (String kwLine : kwLines) {
                if (kwLine.startsWith("#")){
                    continue;
                }
                CrawlerDomainKeywordCommand crawlerDomainKeywordCommand = new CrawlerDomainKeywordCommand("192.168.1.215",9599);

                CrawlerDomainKeys crawlerDomainKeys = new CrawlerDomainKeys();
                crawlerDomainKeys.setDomain(domian);
                crawlerDomainKeys.setKeyword(kwLine);
                crawlerDomainKeys.setSite(geelyKwSite);
                crawlerDomainKeys.setStatus(0);
                crawlerDomainKeywordCommand.addOrUpdateKeys(crawlerDomainKeys);

                System.out.println(JSON.toJSONString(kwLine));
            }
        } catch (Exception e){
            System.out.println(e.getMessage());
        }
    }



    public static void userIdSub(){
        try{
            List<String> kwLines = IOUtils.readLines(new FileInputStream("E:\\chance_work\\chance-crawler-development\\crawler-scripts-command\\src\\main\\java\\com\\chance\\cc\\crawler\\development\\command\\meta\\keyword\\weibo\\weibo_subscribe_user_ids.txt"), Charset.forName("UTF-8"));
            String site = "userId";
            for (String kwLine : kwLines) {
                if (kwLine.startsWith("#")){
                    continue;
                }
                CrawlerDomainKeywordCommand crawlerDomainKeywordCommand = new CrawlerDomainKeywordCommand("192.168.1.215",9599);

                CrawlerDomainKeys crawlerDomainKeys = new CrawlerDomainKeys();
                crawlerDomainKeys.setDomain(domian);
                crawlerDomainKeys.setKeyword(kwLine);
                crawlerDomainKeys.setSite(site);
                crawlerDomainKeys.setStatus(0);
                crawlerDomainKeywordCommand.addOrUpdateKeys(crawlerDomainKeys);

                System.out.println(JSON.toJSONString(kwLine));
            }
        } catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
}
